package designpattern.client;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import designpattern.config.MyAnnotationApplicationContext;
import designpattern.responsibility.ConcreteHandler1;
import designpattern.responsibility.Handler;
import designpattern.responsibility.Request;


/**
 * Resiponsibility Pattern Test
 *
 */
@SuppressWarnings("resource")
public class Client {
    public static void main(String[] args) {
        ApplicationContext config =
                new AnnotationConfigApplicationContext(MyAnnotationApplicationContext.class);
        Handler handler = config.getBean(ConcreteHandler1.class);

        Random rn = new Random();
        List<Request> requests = new ArrayList<Request>();
        for (int i = 0; i < 10; i++) {
            requests.add(new Request(rn.nextInt(10), "Client随机的浮点数为" + rn.nextDouble()));
        }

        for (Request request : requests) {
            handler.handlerRequest(request);
        }
    }
}
